package 二叉树相关问题.BST;

import java.util.LinkedList;
import java.util.List;

public class BINode {
    List<Integer> list = new LinkedList<>();
    public TreeNode convertBiNode(TreeNode root) {
        if (root==null)
            return null;
        traverse(root);
        TreeNode treeNode = new TreeNode(list.get(0));
        TreeNode temp=treeNode;
        for (int i = 1; i < list.size(); i++) {
            temp.right=new TreeNode(list.get(i));
            temp.left=null;
            temp=temp.right;
        }
        return treeNode;
    }

    private void traverse(TreeNode root) {
        if (root==null)
            return;
        traverse(root.left);
        list.add(root.val);
        traverse(root.right);
    }
}
